package com.dwy2002.appointment.config;


import com.dwy2002.appointment.interceptor.JwtValidateInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * MVC配置器类
 *
 * @author 杜伟毅
 * @version 1.0
 * @since 2023/10/09
 */
@Configuration
@RequiredArgsConstructor
public class MyInterceptorConfig implements WebMvcConfigurer {
    private final JwtValidateInterceptor jwtValidateInterceptor;

    /**
     * 添加拦截器
     *
     * @param registry 注册表
     * @author 杜伟毅
     * @since 2023/10/9 0009 23:03
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        InterceptorRegistration registration = registry.addInterceptor(jwtValidateInterceptor);
        // 告诉系统，拦截所有
        registration.addPathPatterns("/**")
                // 需要放行的路径
                .excludePathPatterns(
                        "/error",
                        "/users/login",
                        "/users/register"
                );
    }
}
